//
//  ViewController.m
//  04_UIControl
//
//  Created by li cheng on 16/7/19.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UISwitch *switchControl = [[UISwitch alloc] initWithFrame:CGRectMake(10, 10, 100000000000000, 100)];
    // 宽高不影响视图的大小
    switchControl.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:switchControl];
    // 开启时的控件内部颜色
    switchControl.onTintColor = [UIColor redColor];
    // 切换时到关闭时的颜色(null_resettable)
    switchControl.tintColor = nil;
    // 按钮的颜色
    switchControl.thumbTintColor = [UIColor blackColor];
    // iOS7只会没有效果 打开时的效果
    switchControl.onImage = [UIImage imageNamed:@"123.gif"];
    // 关闭时的属性 iOS7之后失
    switchControl.offImage = [UIImage imageNamed:@"123.gif"];
    // 6.判断switchControl的开闭状态
    switchControl.on = NO;
    NSLog(@"%d", switchControl.isOn ? YES : NO);
    [switchControl setOn:YES animated:YES];
    // 7.添加时间(于Button相同)
    [switchControl addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    
    
    UISlider *slier = [[UISlider alloc] initWithFrame:CGRectMake(10, 100, 350, 100)];
    // 高度不影响他,滑动条居中
    slier.backgroundColor = [UIColor blackColor];
    [self.view addSubview:slier];
    // 初始值,开关在的滑条的位置
    slier.value = 0.5f;
    // 给他赋最小值, 最小值是0, 变成原来的0.X
    slier.minimumValue = 0.2f;
    // 给他赋最大值, 最大值是1, 变成原来的0.X
    slier.maximumValue = 0.7f;
    // 最大值那一边的图片
    slier.maximumValueImage = [UIImage imageNamed:@"1234"];
    
    slier.minimumValueImage = nil;
    
    //
    [slier addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    // 已经移动的区域的颜色
    slier.minimumTrackTintColor = [UIColor purpleColor];
    // 还没有移动的区域的颜色
    slier.maximumTrackTintColor = [UIColor redColor];
    // 滑块的颜色
    slier.thumbTintColor = [UIColor blueColor];
    [slier setMaximumTrackImage:[UIImage imageNamed:@"player_slider_playback_right@2x"] forState:UIControlStateNormal];
    [slier setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left@2x"] forState:UIControlStateNormal];
    [slier setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb@2x"] forState:UIControlStateNormal];
    
    
    
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"first", @"second", @"ddd"]];
    // 如果不给frame,系统会自动计算大小,
    NSLog(@"%@", NSStringFromCGRect(segmentedControl.frame));
    segmentedControl.frame = CGRectMake(30, 200, 200, 60);
    // 1.momentary 设置为YES,如果点击选中没有选中的效果
    segmentedControl.momentary = YES;
    segmentedControl.tag = 1000;
    NSInteger numberOfSegment = segmentedControl.numberOfSegments;
    NSLog(@"分段控制器item的个数是%ld", numberOfSegment);
    
    [self.view addSubview:segmentedControl];
    
    
    // 点击Button, 给segment添加新的标题
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(20, 20, 140, 40);
    [self.view addSubview:button];
    button.backgroundColor = [UIColor yellowColor];
    [button addTarget:self action:@selector(addSegmentTitle:) forControlEvents:UIControlEventTouchUpInside];
    // 3. insertSegmentWithTitle:@"sss" atIndex:1 animated:YES
    // 4. remove
    // 5.     setTitle:<#(nullable NSString *)#> forSegmentAtIndex:<#(NSUInteger)#>
    [segmentedControl setTitle:@"iii" forSegmentAtIndex:0];
    // 6. setWidth:90 forSegmentAtIndex:0 默认是0.0
    [segmentedControl setWidth:0 forSegmentAtIndex:0];
    // 7.设置对应下标内容的偏移
    [segmentedControl setContentOffset:CGSizeMake(0, 20) forSegmentAtIndex:2];
    // 8.NO是不能被选中
    [segmentedControl setEnabled:NO forSegmentAtIndex:0];
    // 9.选中下角标
    segmentedControl.selectedSegmentIndex = 1;
    // 10. 文字以及边框颜色
    segmentedControl.tintColor = [UIColor whiteColor];
    // 11. 如果分段控制器的段宽设置为0是, 并且该属性为YES, 系统会自动计算
    segmentedControl.apportionsSegmentWidthsByContent = YES;
    [segmentedControl addTarget:self action:@selector(segmentedControlIndexChange:) forControlEvents:UIControlEventTouchUpInside];
    
    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(100, 400, 100, 60)];
    pageControl.backgroundColor = [UIColor blueColor];
    // 1.分页控制器的页数,默认值是0
    pageControl.numberOfPages = 3;
    // 2.当前页
    pageControl.currentPage = 1;
    // 3.当只有一页的时候隐藏
    pageControl.hidesForSinglePage = YES;
    [self.view addSubview:pageControl];
    // 4.获取到点的大小
    CGSize size = [pageControl sizeForNumberOfPages:1];
    NSLog(@"%@", NSStringFromCGSize(size));
    // 5. 未选中页的颜色
    pageControl.pageIndicatorTintColor = [UIColor greenColor];
    // 6. 当前页的颜色
    pageControl.currentPageIndicatorTintColor = [UIColor redColor];
    // 7. 绑定事件
    [pageControl addTarget:self action:@selector(pageControlChange:) forControlEvents:UIControlEventValueChanged];
    // 8.关闭pag自动切换 知道调用 updateCurrentPageDisplay
    pageControl.defersCurrentPageDisplay = YES;
    
    
    
    
    
    
    
    
}

- (void)pageControlChange:(UIPageControl *)pageControlChange{
    NSLog(@"Change");
    [pageControlChange updateCurrentPageDisplay];
}


//
- (void)segmentedControlIndexChange:(UISegmentedControl *)segmentedControl{
//    switch (<#expression#>) {
//        case <#constant#>:
//            <#statements#>
//            break;
//            
//        default:
//            break;
//    }
}

- (void)addSegmentTitle:(UIButton *)button{
    UISegmentedControl *segment = [self.view viewWithTag:1000];
    [segment insertSegmentWithTitle:@"sss" atIndex:1 animated:YES];
}

- (void)sliderAction:(UISlider *)sliderControl{
    NSLog(@"%f", sliderControl.value);
}

- (void)switchAction:(UISwitch *)switchControl{
    // 根据swith的状态, 决定触发什么样的事件
    if(switchControl.on == YES) {
        NSLog(@"开");
    } else {
        NSLog(@"关");
    }
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
